<?php
/**
 * @author Sergey Dostovalov
 */
class MarcParseException extends Exception{
    
    const UNKNOWN_ERROR = 0;
    const INVALID_FILE = -1;
    const WRONG_RECORD_LENGTH = -2;
    const INVALID_RECORD_TERMINATOR = -3;
    const WRONG_LEADER = -4;
    const BASE_ADDRESS_NOT_FOUND = -5;
    const BASE_ADDRESS_INVALID = -6;
    const DIRECTORY_NOT_FOUNDED = -7;
    const INVALID_RECORD_DIRECTORY = -8;
    const TAG_ERROR = -9;
    private $messageCode;
    
    public static $messages = array(
        self::UNKNOWN_ERROR => 'Unknown error',
        self::INVALID_FILE => 'Invalid input file "%filename%"',
        self::WRONG_RECORD_LENGTH => 'Wrong record length',
        self::INVALID_RECORD_TERMINATOR => 'Invalid record terminator',
        self::WRONG_LEADER => 'Wrong record leader',
        self::BASE_ADDRESS_NOT_FOUND => 'Base address not found',
        self::BASE_ADDRESS_INVALID => 'Base Address invalid',
        self::DIRECTORY_NOT_FOUNDED => 'Directory not founded',
        self::INVALID_RECORD_DIRECTORY => 'Invalid record directory',
        self::TAG_ERROR => 'Tag of field should consist of three digits and is located in the interval from 001 to 999',
    );
    
    public function __construct($messageCode = 0, $errorLevel = 0, $errorFile = '', $errorLine = 0)
    {
        $this->messageCode = $messageCode;
        parent::__construct(self::$messages[$this->messageCode], $errorLevel);
        $this->file = $errorFile;
        $this->line = $errorLine;
   }

   public function getMessageCode()
   {
       return $messageCode;
   }
    
}

class MarcFieldNotExsist extends Exception {
    public function  __construct($tag = '')
    {
        parent::__construct('Field with tag '.$tag.' not exsist');
    }
}

class MarcSubfieldNotExist extends Exception {
    public function  __construct($code = '')
    {
        parent::__construct('Subfield with code '.$code.' not exsist');
    }
}
class MarcConverterException extends Exception {

}
class MarcException extends Exception {

}
?>
